/**
 * JAVACC DEMO 1.0
 * @copy right dwusoft company All rights reserved. 
 * @Package com.apache.passport.aop  
 */
package com.apache.passport.aop;

import java.util.List;

import org.slf4j.Logger;
import org.slf4j.LoggerFactory;

import com.apache.api.vo.ParamsVo;
import com.apache.database.constant.SystemTools;
import com.apache.database.constant.Validator;
import com.apache.passport.common.FileUtils;
import com.apache.passport.entity.LoginInfo;

/**
 * description:  定时器执行任务
 * @author Hou Dayu 创建时间：2015-1-16  
 * @Copyright(c)2014:
 */
public class LoginAopTimer {
	private static final Logger log = LoggerFactory.getLogger(LoginAopTimer.class);

	/**
	 * description:  从缓存中取出所有对象,且保存到文件中,定时器会调用此方法
	 * @param param  
	 * @author Hou Dayu 
	 * @update 2015-1-16
	 */
	public void useAllCacheBackFile() {
		log.info("passport msg:[{}]", "定时器执行开始...");
		ParamsVo<LoginInfo> param = new ParamsVo<LoginInfo>();
		//去除当前缓存中所有的key
		List<String> lst = SystemTools.getInstance().getCache("loginLogCache").getAllKeys();
		List<Object> listObj = SystemTools.getInstance().getCache("loginLogCache").getObjects(lst);
		if (!Validator.isEmpty(listObj)) {
			for (int i = 0; i < listObj.size(); i++) {
				LoginInfo info = (LoginInfo) listObj.get(i);
				param.setObj(info);
				FileUtils.getInstance().createLoginFile(param);
			}
			SystemTools.getInstance().getCache("loginLogCache").removeAll();
		}
	}
}
